import Vue from 'vue'
import Router from 'vue-router'

// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading

Vue.use(Router)

/* Layout */
import Layout from '../views/layout/Layout'

/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirect in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    title: 'title'               the name show in subMenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar
    breadcrumb: false            if false, the item will hidden in breadcrumb(default is true)
  }
**/
export const constantRouterMap = [
  { path: '/login', component: () => import('@/views/login/index'), hidden: true },
  { path: '/404', component: () => import('@/views/404'), hidden: true },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    name: 'Dashboard',
    hidden: false,
    children: [{
      path: 'dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '电商后台管理系统', icon: 'dashboard' }
    }]
  },
  // 科技-产业
  {
    path: '/sys',
    component: Layout,
    redirect: '/sys/user/list',
    name: 'TechIndustry',
    meta: { title: '系统管理', icon: 'nested' },
    children: [
      {
        path: 'user',
        name: 'UserManager',
        component: () => import('@/views/sys/user'),
        meta: { title: '用户管理',icon: 'user' },
        children: [
          {
            path: 'list',
            component: () => import('@/views/sys/user/list'),
            name: 'UserList',
            meta: { title: '用户列表',icon: 'list'},
          },
          {
            path: 'detail/:id',
            name: 'UserDetail',
            component: () => import('@/views/sys/user/detail'),
            meta: { title: '用户详情',icon: 'form'},
            hidden: true
          },
          {
            path: 'add',
            component: () => import('@/views/sys/user/add'),
            name: 'UserAdd',
            meta: { title: '新增用户',icon: 'form'}
          },
          {
            path: 'update/:id',
            component: () => import('@/views/sys/user/update'),
            name: 'UserUpate',
            meta: { title: '更新用户',icon: 'form'},
            hidden: true
          },
        ]
      },
      {
        path: 'role',
        name: 'Role',
        component: () => import('@/views/sys/role'),
        meta: { title: '角色管理',icon: 'people'},
        children: [
          {
            path: 'list',
            name: 'RoleList',
            component: () => import('@/views/sys/role/list'),
            meta: { title: '角色列表',icon: 'list' }
          },
          {
            path: 'add',
            name: 'AddRole',
            component: () => import('@/views/sys/role/add'),
            meta: { title: '新增角色',icon: 'form'}
          },
          {
            path: 'detail/:id',
            name: 'RoleDetail',
            component: () => import('@/views/sys/role/detail'),
            meta: { title: '角色详情'},
            hidden: true
          },
          {
            path: 'update/:id',
            name: 'RoleUpdate',
            component: () => import('@/views/sys/role/update'),
            meta: { title: '更新角色'},
            hidden: true
          }
        ]
      },
      {
        path: 'menu',
        name: 'Menu',
        component: () => import('@/views/sys/menu'),
        meta: { title: '菜单管理',icon: 'table'},
        children: [
          {
            path: 'list',
            name: 'MenuList',
            component: () => import('@/views/sys/menu/list'),
            meta: { title: '菜单列表',icon: 'list' }
          },
          {
            path: 'add',
            name: 'AddMenu',
            component: () => import('@/views/sys/menu/add'),
            meta: { title: '新增菜单',icon: 'form'}
          },
          {
            path: 'detail/:id',
            name: 'MenuDetail',
            component: () => import('@/views/sys/menu/detail'),
            meta: { title: '菜单详情'},
            hidden: true
          },
          {
            path: 'update/:id',
            name: 'MenuUpdate',
            component: () => import('@/views/sys/menu/update'),
            meta: { title: '更新菜单'},
            hidden: true
          }
        ]
      }
    ]
  },
  // 商品管理
  {
    path: '/goods',
    component: Layout,
    redirect: '/goods',
    name: 'Goods',
    meta: { title: '商品管理', icon: 'excel' },
    children: [
      {
        path: 'list',
        name: 'GoodsList',
        component: () => import('@/views/goods/index'),
        meta: { title: '商量列表',icon: 'list' }
      },
      {
        path: 'detail/:id',
        name: 'Detail',
        component: () => import('@/views/goods/detail'),
        meta: { title: '商品详情', noCache: true },
        hidden: true
      },
      {
        path: 'add',
        name: 'Add',
        component: () => import('@/views/goods/addOrUpdate'),
        meta: { title: '商品新增',icon: 'form' }
      },
      {
        path: 'update/:id',
        name: 'Update',
        component: () => import('@/views/goods/addOrUpdate'),
        meta: { title: '商品更新' },
        hidden: true
      }
    ]
  },
  // 可视化管理
  {
    path: '/map',
    component: Layout,
    redirect: '/map',
    name: 'Map',
    meta: { title: '可视化管理', icon: 'excel' },
    children: [
      {
        path: 'list',
        name: 'ChinaMap',
        component: () => import('@/views/map/chinaMap'),
        meta: { title: '中国地图',icon: 'list' }
      },
      {
        path: 'dynamic',
        name: 'Dynamic',
        component: () => import('@/views/map/dynamic'),
        meta: { title: '动态数据',icon: 'form' }
      }
    ]
  },
  { path: '*', redirect: '/404', hidden: true }
]

export default new Router({
  // nginx二级域名配置
  base: '/gvsys/',
  // mode: 'history', //后端支持可开
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})
